package com.foxitcloud.webpdf.utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.log4j.Logger;

/**
 * @author shaojie_zhuo
 * @version 1.0 String Utils.
 */
public final class FXStringUtils {

	private static final Logger log = Logger.getLogger(FXStringUtils.class);

	/**
	 * Check whether the string is empty or null.(for Java 1.5)
	 * 
	 * @param strValue
	 *            string to check.
	 * @return return true if the string is null or empty, otherwise return
	 *         false.
	 */
	public static boolean IsNullOrEmpty(String strValue) {
		if (strValue == null || strValue.isEmpty())
			return true;
		else
			return false;
		
	}

	/**
	 * 将InputStream转换成某种字符编码的String
	 * 
	 * @param in
	 * @param encoding
	 * @return
	 * @throws Exception
	 */
	public static String inputStreamTOString(InputStream in, String encoding) {
		ByteArrayOutputStream outStream = new ByteArrayOutputStream();
		String stringInfo = "";
		byte[] data = new byte[1024];
		int count = -1;
		try {
			while ((count = in.read(data, 0, 1024)) != -1) {
				outStream.write(data, 0, count);
			}
			stringInfo = new String(outStream.toByteArray(), encoding);
		} catch (IOException e) {
			log.warn(e);
			return null;
		} finally {
			try {
				in.close();
				outStream.close();
			} catch (IOException e) {
				log.warn(e);
				return null;
			}
		}
		data = null;
		return stringInfo;
	}

	public static boolean shareContains(String paremt){
		return paremt.contains("-");
	}
}
